package cn.xeblog.plugin.game.chess;


import cn.xeblog.commons.entity.game.chess.ChessDTO;
import cn.xeblog.plugin.util.NotifyUtils;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 游戏逻辑
 * <p>
 * 作者：我是小木鱼（Lag）<a href="https://blog.csdn.net/lag_csdn/article/details/122324799">原文地址</a></p>
 * <p> 作者：Hao.
 */
public class GameLogic {
    /**
     * 游戏面板
     */
    GamePanel gamePanel;

    /**
     * 最大搜索深度
     */
    int maxDepth = 1;

    /**
     * 电脑AI要走的位置
     */
    Map<String, String> mapAiChess = new HashMap<>();

    /**
     * 初始化
     *
     * @param gamePanel 游戏面板
     */
    public GameLogic(GamePanel gamePanel) {
        this.gamePanel = gamePanel;
    }

    /**
     * 得到X像素所对应的列坐标
     *
     * @param x 横坐标
     * @return 列坐标，返回-1表示没找到
     */
    private int getColumn(int x) {
        //先判断靠哪列近些 (当前离起点的距离=x - this.gamePanel.gridsLeftX +露在外面的一半棋子)
        int column = (x - this.gamePanel.gridsLeftX + this.gamePanel.gridSize / 2) / this.gamePanel.gridSize;
        // 再判断是否在有效范围内(起始点+当前棋盘的宽度)
        int posX = this.gamePanel.gridsLeftX + column * this.gamePanel.gridSize;
        if (x > (posX - this.gamePanel.chessSize / 2) && x < (posX + this.gamePanel.chessSize / 2)) {
        } else {
            column = -1;
        }

        return column;
    }

    /**
     * 得到Y像素所对应的行坐标
     *
     * @param y 纵坐标
     * @return 行坐标，返回-1表示没找到
     */
    private int getRow(int y) {
        // 先判断靠哪行近些(当前离起点的距离=y - this.gamePanel.gridsLefty +露在外面的一半棋子)
        int row = (y - this.gamePanel.gridsTopY + this.gamePanel.gridSize / 2) / this.gamePanel.gridSize;
        // 再判断是否在有效范围内(起始点+当前棋盘的高度)
        int posY = this.gamePanel.gridsTopY + row * this.gamePanel.gridSize;
        if (y > (posY - this.gamePanel.chessSize / 2) && y < (posY + this.gamePanel.chessSize / 2)) {
        } else {
            row = -1;
        }

        return row;
    }

    /**
     * 功能：将军提示<br>
     */
    boolean check(boolean color) {
        int type = color ? 1 : 0;
        // 遍历全体棋子，不知道将哪头的军
        for (int i = 0; i < this.gamePanel.mapChess.length; i++) {
            // 获取棋子的移动路线
            this.getMoveRoute(this.gamePanel.mapChess[i]);
            // 遍历棋子移动路线
            for (int j = 0; j < this.gamePanel.listMove.size(); j++) {
                // 具体坐标
                Map<String, Integer> map = this.gamePanel.listMove.get(j);
                // 路线上存在的棋子
                int index = this.gamePanel.chessBoradState[map.get("row")][map.get("column")];
                // 不存在棋子跳过
                if (index == -1) {
                    continue;
                }

                Map<String, String> beEatenChess = this.gamePanel.mapChess[index];
                if (!"king".equals(beEatenChess.get("type"))) {
                    continue;
                }

                if (gamePanel.chineseChess.chessCache.currentMode == ChessCache.Mode.ONLINE) {

                    // 走完后，自己被将军
                    if (Integer.parseInt(beEatenChess.get("color")) == type) {
                        NotifyUtils.info("提示", "不能送将！");
                        this.undo();
                        return true;
                    }

                    // 将军

                    // 这次将军是否意味着绝杀
                    if (lore(Integer.parseInt(beEatenChess.get("color")))) {
                        NotifyUtils.info("提示", "绝杀！");
                        beEatenChess.put("dead", "T");
                        break;
                    }

                    if (gamePanel.chineseChess.chessCache.currentPlayer != color) {
                        NotifyUtils.info("提示", "将军！");
                    }
                } else {
                    NotifyUtils.info("提示", "将军！");
                }
                break;
            }
        }

        // 清空移动路线
        this.gamePanel.listMove.clear();
        // 刷新界面
        this.gamePanel.repaint();
        return false;
    }

    /**
     * 刀下留将
     *
     * @param color 被将军的一方
     * @author Hao.
     * @date 2022/9/23 9:39
     */
    private boolean lore(int color) {
        // 老将能否获救
        for (int a = 0; a < this.gamePanel.mapChess.length; a++) {
            // 用我方的棋子来模拟
            if (Integer.parseInt(this.gamePanel.mapChess[a].get("color")) != color) {
                continue;
            }
            for (int row = 0; row < GamePanel.GRID_ROWS; row++) {
                for (int column = 0; column < GamePanel.GRID_COLUMNS; column++) {
                    if (!this.isAbleToMove(this.gamePanel.mapChess[a], row, column)) {
                        continue;
                    }
                    this.moveTo(this.gamePanel.mapChess[a], row, column);
                    // 移动后，校验是否被绝杀
                    if (!checkLore(color)) {
                        // 逃出生天
                        this.undoStep();
                        return false;
                    }
                    // 这一步是死局呀。。。 赶紧换个路线
                }
            }
        }
        return true;
    }

    /**
     * 老将必须死！
     *
     * @param color 被将军的一方
     * @author Hao.
     * @date 2022/9/23 9:39
     */
    boolean checkLore(int color) {
        // 哦~ 你走完了，那好，我又来将军了
        for (int i = 0; i < this.gamePanel.mapChess.length; i++) {
            this.getMoveRoute(this.gamePanel.mapChess[i]);
            for (int j = 0; j < this.gamePanel.listMove.size(); j++) {

                Map<String, Integer> map = this.gamePanel.listMove.get(j);
                int index = this.gamePanel.chessBoradState[map.get("row")][map.get("column")];
                if (index == -1) {
                    continue;
                }

                Map<String, String> beEatenChess = this.gamePanel.mapChess[index];
                if (!"king".equals(beEatenChess.get("type"))) {
                    continue;
                }

                // 老将逃不掉了
                if (Integer.parseInt(beEatenChess.get("color")) == color) {
                    this.undoStep();
                    return true;
                }
            }
        }
        this.gamePanel.listMove.clear();
        this.gamePanel.repaint();
        return false;
    }

    /**
     * 判断棋子是否可以放到目标位置
     * <p>备注：点空位或对方棋子上，已方棋子略</p>
     *
     * @param _mapChess  棋子
     * @param _newRow    目标行位置
     * @param _newColumn 目标列位置
     * @return true, 可以移动至目录位置，否则，false
     */
    boolean isAbleToMove(Map<String, String> _mapChess, int _newRow, int _newColumn) {
        // 移动前行位置
        int oldRow = -1;
        // 移动前列位置
        int oldColulmn = -1;
        // 目标索引
        int index = -1;
        // 棋子类型
        String type = "";
        // 棋子方向（T-上方，B-下方）
        String direction = "";

        //死亡棋子不能移动
        if ("T".equals(_mapChess.get("dead"))) {
            return false;
        }

        oldRow = Integer.parseInt(_mapChess.get("newRow"));
        oldColulmn = Integer.parseInt(_mapChess.get("newColumn"));
        type = _mapChess.get("type");
        direction = _mapChess.get("direction");
        index = this.gamePanel.chessBoradState[_newRow][_newColumn];

        // 不能吃相同颜色的子，即自己一方的棋子
        if (index != -1 && Integer.parseInt(this.gamePanel.mapChess[index].get("color")) == Integer.parseInt(_mapChess.get("color"))) {
            return false;
        }

        // 不能吃自身
        if (oldRow == _newRow && oldColulmn == _newColumn) {
            return false;
        }

        // 将帅
        if ("king".equals(type)) {
            //  目标棋子是将帅并且在同一列上,即将帅不能露脸
            if (index != -1 && "king".equals(this.gamePanel.mapChess[index].get("type")) && oldColulmn == _newColumn) {
                //判断中间是否有棋子
                int count = 0;
                int min = Math.min(oldRow, _newRow);
                int max = Math.max(oldRow, _newRow);
                for (int row = min + 1; row < max; row++) {
                    // 存在棋子,棋子计数+1
                    if (this.gamePanel.chessBoradState[row][_newColumn] != -1) {
                        count++;
                    }
                }
                if (count == 0) {
                    return true;
                }
            }
            // 不能出九宫
            if ((_newRow > 2 && _newRow < 7) || _newColumn < 3 || _newColumn > 5) {
                return false;
            }
            // 一次只能走一格
            if (Math.abs(_newRow - oldRow) > 1 || Math.abs(_newColumn - oldColulmn) > 1) {
                return false;
            }
            // 不能走斜线
            if ((_newRow - oldRow) * (_newColumn - oldColulmn) != 0) {
                return false;
            }
        } else if ("guard".equals(type)) { // 士仕
            //不能出九宫
            if ((_newRow > 2 && _newRow < 7) || _newColumn < 3 || _newColumn > 5) {
                return false;
            }
            //一次只能走一格
            if (Math.abs(_newRow - oldRow) > 1 || Math.abs(_newColumn - oldColulmn) > 1) {
                return false;
            }
            //不能走横线或竖线
            if ((_newRow - oldRow) * (_newColumn - oldColulmn) == 0) {
                return false;
            }
        } else if ("elephant".equals(type)) { // 象相
            // 不能越界
            if ("T".equals(direction)) {
                if (_newRow > 4) {
                    return false;
                }
            } else {
                if (_newRow < 5) {
                    return false;
                }
            }
            // 不能走横线或竖线
            if ((_newRow - oldRow) * (_newColumn - oldColulmn) == 0) {
                return false;
            }
            // 一次只能走二格
            if (Math.abs(_newRow - oldRow) != 2 || Math.abs(_newColumn - oldColulmn) != 2) {
                return false;
            }
            // 是否堵象眼
            if (this.gamePanel.chessBoradState[Math.min(oldRow, _newRow) + 1][Math.min(oldColulmn, _newColumn) + 1] != -1) {
                return false;
            }
        } else if ("horse".equals(type)) { // 马（8种跳法，4种别腿）
            // 必须走日字格
            if (Math.abs((_newRow - oldRow)) * Math.abs((_newColumn - oldColulmn)) != 2) {
                return false;
            }
            // 向上跳
            if (_newRow - oldRow == -2) {
                if (this.gamePanel.chessBoradState[oldRow - 1][oldColulmn] != -1) {
                    return false;
                }
            }
            // 向下跳
            if (_newRow - oldRow == 2) {
                if (this.gamePanel.chessBoradState[oldRow + 1][oldColulmn] != -1) {
                    return false;
                }
            }
            // 向左跳
            if (_newColumn - oldColulmn == -2) {
                if (this.gamePanel.chessBoradState[oldRow][oldColulmn - 1] != -1) {
                    return false;
                }
            }
            // 向右跳
            if (_newColumn - oldColulmn == 2) {
                if (this.gamePanel.chessBoradState[oldRow][oldColulmn + 1] != -1) {
                    return false;
                }
            }
        } else if ("rook".equals(type)) { // 车
            // 不能走斜线
            if ((_newRow - oldRow) * (_newColumn - oldColulmn) != 0) {
                return false;
            }
            // 竖走
            if (_newColumn == oldColulmn) {
                // 判断中间是否有棋子
                int min = Math.min(oldRow, _newRow);
                int max = Math.max(oldRow, _newRow);
                for (int row = min + 1; row < max; row++) {
                    if (this.gamePanel.chessBoradState[row][_newColumn] != -1) {
                        return false;
                    }
                }
            }
            // 横走
            if (_newRow == oldRow) {
                // 判断中间是否有棋子
                int min = Math.min(oldColulmn, _newColumn);
                int max = Math.max(oldColulmn, _newColumn);
                for (int column = min + 1; column < max; column++) {
                    if (this.gamePanel.chessBoradState[_newRow][column] != -1) {
                        return false;
                    }
                }
            }
        } else if ("cannon".equals(type)) { // 炮
            int count = 0;
            // 不能走斜线
            if ((_newRow - oldRow) * (_newColumn - oldColulmn) != 0) {
                return false;
            }
            // 竖走
            if (_newColumn == oldColulmn) {
                //判断中间是否有棋子
                int min = Math.min(oldRow, _newRow);
                int max = Math.max(oldRow, _newRow);
                for (int row = min + 1; row < max; row++) {
                    if (this.gamePanel.chessBoradState[row][_newColumn] != -1) {
                        count++;
                    }
                }
            }
            // 横走
            if (_newRow == oldRow) {
                //判断中间是否有棋子
                int min = Math.min(oldColulmn, _newColumn);
                int max = Math.max(oldColulmn, _newColumn);
                for (int column = min + 1; column < max; column++) {
                    if (this.gamePanel.chessBoradState[_newRow][column] != -1) {
                        count++;
                    }
                }
            }
            // 开始判断是否可以移动或吃棋子
            if (count > 1) {
                return false;
            } else if (count == 1) {  // 打空炮的不要
                if (this.gamePanel.chessBoradState[_newRow][_newColumn] == -1) {
                    return false;
                }
            } else {
                if (this.gamePanel.chessBoradState[_newRow][_newColumn] != -1) {
                    return false;
                }
            }
        } else if ("soldier".equals(type)) { // 卒兵
            //不能走斜线
            if ((_newRow - oldRow) * (_newColumn - oldColulmn) != 0) {
                return false;
            }
            //一次只能走一格
            if (Math.abs(_newRow - oldRow) > 1 || Math.abs(_newColumn - oldColulmn) > 1) {
                return false;
            }
            //小卒过河不回头
            if ("T".equals(direction)) {// 上方
                // 过河了
                if (oldRow > 4) {
                    if (_newRow < oldRow) {  //不许向后退
                        return false;
                    }
                } else {
                    //只能往前走
                    if (_newColumn == oldColulmn && _newRow > oldRow) {
                    } else {
                        return false;
                    }
                }
            } else { // 下方
                if (oldRow < 5) { // 过河了
                    if (_newRow > oldRow) {  // 不许向后退
                        return false;
                    }
                } else {
                    if (_newColumn == oldColulmn && _newRow < oldRow) { // 只能往前走
                    } else {
                        return false;
                    }
                }
            }
        }

        return true;
    }

    /**
     * 功能：将下完的棋子信息复制一份存储到下棋列表中，悔棋用<br>
     * 备注：因为是对象引用，所以必须复制b<br>
     */
    private void addList(Map<String, String> _mapChess) {
        Map<String, String> map = new HashMap<>();
        map.put("index", _mapChess.get("index"));
        map.put("color", _mapChess.get("color"));
        map.put("type", _mapChess.get("type"));
        map.put("name", _mapChess.get("name"));
        map.put("number", _mapChess.get("number"));
        map.put("direction", _mapChess.get("direction"));
        map.put("oldOldRow", _mapChess.get("oldOldRow"));
        map.put("oldOldColumn", _mapChess.get("oldOldColumn"));
        map.put("oldRow", _mapChess.get("oldRow"));
        map.put("oldColumn", _mapChess.get("oldColumn"));
        map.put("newRow", _mapChess.get("newRow"));
        map.put("newColumn", _mapChess.get("newColumn"));
        map.put("dead", _mapChess.get("dead"));
        map.put("oldEatIndex", _mapChess.get("oldEatIndex"));
        map.put("eatIndex", _mapChess.get("eatIndex"));
        this.gamePanel.listChess.add(map);
    }

    /**
     * 功能：悔棋具体步骤<br>
     */
    void undoStep() {
        if (this.gamePanel.isGameOver) {
            return;
        }
        if (this.gamePanel.listChess.size() < 1) {
            return;
        }

        //得到最后一步棋信息
        Map<String, String> mapLast = this.gamePanel.listChess.get(this.gamePanel.listChess.size() - 1);
        int index = Integer.parseInt(mapLast.get("index"));
        int oldOldRow = Integer.parseInt(mapLast.get("oldOldRow"));
        int oldOldColumn = Integer.parseInt(mapLast.get("oldOldColumn"));
        int oldRow = Integer.parseInt(mapLast.get("oldRow"));
        int oldColumn = Integer.parseInt(mapLast.get("oldColumn"));
        int newRow = Integer.parseInt(mapLast.get("newRow"));
        int newColumn = Integer.parseInt(mapLast.get("newColumn"));
        int oldEatIndex = Integer.parseInt(mapLast.get("oldEatIndex"));
        int eatIndex = Integer.parseInt(mapLast.get("eatIndex"));

        // 开始退回
        this.gamePanel.mapChess[index].put("newRow", Integer.toString(oldRow));
        this.gamePanel.mapChess[index].put("newColumn", Integer.toString(oldColumn));
        this.gamePanel.mapChess[index].put("oldRow", Integer.toString(oldOldRow));
        this.gamePanel.mapChess[index].put("oldColumn", Integer.toString(oldOldColumn));
        this.gamePanel.mapChess[index].put("oldOldRow", "-1");
        this.gamePanel.mapChess[index].put("oldOldColumn", "-1");
        this.gamePanel.mapChess[index].put("dead", "F");
        this.gamePanel.mapChess[index].put("eatIndex", Integer.toString(oldEatIndex));
        this.gamePanel.mapChess[index].put("oldEatIndex", "-1");
        // 改变坐标
        this.gamePanel.labelChess[index].setBounds(this.gamePanel.gridsLeftX + oldColumn * this.gamePanel.gridSize - this.gamePanel.chessSize / 2, this.gamePanel.gridsTopY + oldRow * this.gamePanel.gridSize - this.gamePanel.chessSize / 2, this.gamePanel.chessSize, this.gamePanel.chessSize);
        this.gamePanel.chessBoradState[oldRow][oldColumn] = index;
        //判断是否吃棋子了
        if (eatIndex == -1) { //未吃棋子
            this.gamePanel.chessBoradState[newRow][newColumn] = -1;
        } else {//吃棋子了，给我吐出来
            this.gamePanel.mapChess[eatIndex].put("dead", "F");
            this.gamePanel.labelChess[eatIndex].setBounds(this.gamePanel.gridsLeftX + newColumn * this.gamePanel.gridSize - this.gamePanel.chessSize / 2, this.gamePanel.gridsTopY + newRow * this.gamePanel.gridSize - this.gamePanel.chessSize / 2, this.gamePanel.chessSize, this.gamePanel.chessSize);
            this.gamePanel.chessBoradState[newRow][newColumn] = eatIndex;
        }
        // 移除落子信息
        this.gamePanel.listChess.remove(this.gamePanel.listChess.size() - 1);
    }

    /**
     * 悔棋<br>
     */
    public void undo() {

        // 悔几步
        int i = 1;

        if (gamePanel.chineseChess.chessCache.currentBattle == ChessCache.Battle.PVC) {
            // 人机多悔一步
            i++;
        }

        Map<String, String> mapLast = this.gamePanel.listChess.get(this.gamePanel.listChess.size() - i);
        int index = Integer.parseInt(mapLast.get("index"));
        int color = Integer.parseInt(mapLast.get("color"));
        int oldRow = Integer.parseInt(mapLast.get("oldRow"));
        int oldColumn = Integer.parseInt(mapLast.get("oldColumn"));

        // 离线 红黑棋悔棋数皆减1
        if (gamePanel.chineseChess.chessCache.currentMode == ChessCache.Mode.OFFLINE) {
            this.gamePanel.jb_undo.setEnabled(false);
        }

        // 后退一步
        this.undoStep();

        if (gamePanel.chineseChess.chessCache.currentBattle == ChessCache.Battle.PVC) {
            // 人机多悔一步
            this.undoStep();
        }

        //重新生成落子指示器
        this.gamePanel.mapPointerChess.put("row", oldRow);
        this.gamePanel.mapPointerChess.put("column", oldColumn);
        this.gamePanel.mapPointerChess.put("color", color);
        this.gamePanel.mapPointerChess.put("show", 1);
        this.gamePanel.isFirstClick = false;
        this.gamePanel.firstClickChess = this.gamePanel.mapChess[index];

        //显示移动路线图
        this.getMoveRoute(this.gamePanel.firstClickChess);

        if (color == ChessCache.Player.RED.getValue()) {
            this.gamePanel.jlb_redStateText.setText("悔棋中");
            this.gamePanel.jlb_blackStateText.setText(getOtherSidePrompt(this.gamePanel.listChess.get(this.gamePanel.listChess.size() - 1)));
        } else {
            this.gamePanel.jlb_redStateText.setText(getOtherSidePrompt(this.gamePanel.listChess.get(this.gamePanel.listChess.size() - 1)));
            this.gamePanel.jlb_blackStateText.setText("悔棋中");
        }

        //刷新
        this.gamePanel.repaint();
    }

    /**
     * 对当前局面进行估分
     * <p>备注：若电脑下的棋则（电脑分-玩家分），反之（玩家分-电脑分）
     *
     * @param chessBoradMap 棋盘状态信息
     */
    private int evaluation(int[][] chessBoradMap) {
        // 基础分
        final int BASE_ROOK = 500;
        final int BASE_HORSE = 350;
        final int BASE_ELEPHANT = 250;
        final int BASE_GUARD = 250;
        final int BASE_KING = 10000;
        final int BASE_CANNON = 350;
        final int BASE_SOLDIER = 100;
        // 灵活分（每多一个可走位置的相应加分）
        final int FLEXIBLE_ROOK = 6;
        final int FLEXIBLE_HORSE = 12;
        final int FLEXIBLE_ELEPHANT = 1;
        final int FLEXIBLE_GUARD = 1;
        final int FLEXIBLE_KING = 0;
        final int FLEXIBLE_CANNON = 6;
        final int FLEXIBLE_SOLDIER = 15;
        // ------------------------ 其他 ------------------------
        // 总评估分数
        int score = 0;
        // 红旗评估分数
        int redScore = 0;
        // 黑棋评估分数
        int blackScore = 0;

        // 判断该谁下棋
        int nextColor = gamePanel.getNextChessColor();

        // 所有棋子循环
        for (int m = 0; m < this.gamePanel.mapChess.length; m++) {
            // 如果该棋子死亡则略过
            if ("T".equals(this.gamePanel.mapChess[m].get("dead"))) {
                continue;
            }

            // 得到相关参数
            String type = this.gamePanel.mapChess[m].get("type");
            int color = Integer.parseInt(this.gamePanel.mapChess[m].get("color"));
            String direction = this.gamePanel.mapChess[m].get("direction");
            int newRow = Integer.parseInt(this.gamePanel.mapChess[m].get("newRow"));
            int newColumn = Integer.parseInt(this.gamePanel.mapChess[m].get("newColumn"));

            // 加基础分
            if ("rook".equals(type)) {  // 车
                if (color == ChessCache.Player.BLACK.getValue()) {
                    blackScore = blackScore + BASE_ROOK;
                } else {
                    redScore = redScore + BASE_ROOK;
                }
            } else if ("horse".equals(type)) {  // 马
                if (color == ChessCache.Player.BLACK.getValue()) {
                    blackScore = blackScore + BASE_HORSE;
                } else {
                    redScore = redScore + BASE_HORSE;
                }
            } else if ("elephant".equals(type)) {  // 象相
                if (color == ChessCache.Player.BLACK.getValue()) {
                    blackScore = blackScore + BASE_ELEPHANT;
                } else {
                    redScore = redScore + BASE_ELEPHANT;
                }
            } else if ("guard".equals(type)) { // 士仕
                if (color == ChessCache.Player.BLACK.getValue()) {
                    blackScore = blackScore + BASE_GUARD;
                } else {
                    redScore = redScore + BASE_GUARD;
                }
            } else if ("king".equals(type)) { // 将帅
                if (color == ChessCache.Player.BLACK.getValue()) {
                    blackScore = blackScore + BASE_KING;
                } else {
                    redScore = redScore + BASE_KING;
                }
            } else if ("cannon".equals(type)) { // 炮
                if (color == ChessCache.Player.BLACK.getValue()) {
                    blackScore = blackScore + BASE_CANNON;
                } else {
                    redScore = redScore + BASE_CANNON;
                }
            } else if ("soldier".equals(type)) {  // 卒兵
                if (color == ChessCache.Player.BLACK.getValue()) {
                    blackScore = blackScore + BASE_SOLDIER;
                } else {
                    redScore = redScore + BASE_SOLDIER;
                }
            }

            // 加过河分
            if ("soldier".equals(type)) {  // 卒兵
                int riverScore = 0;
                if ("T".equals(direction)) {  // 上方
                    if (newRow > 4 && newRow < 9) { // 过河了（不要最底框那行）
                        riverScore = 70;
                        if (newRow >= 6) {
                            if (newColumn >= 2 && newColumn <= 6) {
                                if (newRow >= 7 && newRow <= 8 && newColumn >= 3 && newColumn <= 5) {
                                    riverScore = riverScore + 50;
                                } else {
                                    riverScore = riverScore + 40;
                                }
                            }
                        }
                    }
                } else {  // 下方
                    if (newRow > 0 && newRow < 5) { // 过河了（不要最顶框那行）
                        riverScore = 70;
                        if (newRow <= 3) {
                            if (newColumn >= 2 && newColumn <= 6) {
                                if (newRow >= 1 && newRow <= 2 && newColumn >= 3 && newColumn <= 5) {
                                    riverScore = riverScore + 50;
                                } else {
                                    riverScore = riverScore + 40;
                                }
                            }
                        }

                    }
                }
                if (color == ChessCache.Player.BLACK.getValue()) {
                    blackScore = blackScore + riverScore;
                } else {
                    redScore = redScore + riverScore;
                }
            }

            // 该棋子可以走的位置
            for (int row = 0; row < GamePanel.GRID_ROWS; row++) {
                for (int column = 0; column < GamePanel.GRID_COLUMNS; column++) {
                    if (this.isAbleToMove(this.gamePanel.mapChess[m], row, column)) {
                        // 加适应分
                        if ("rook".equals(type)) { // 车
                            if (color == ChessCache.Player.BLACK.getValue()) {
                                blackScore = blackScore + FLEXIBLE_ROOK;
                            } else {
                                redScore = redScore + FLEXIBLE_ROOK;
                            }
                        } else if ("horse".equals(type)) { // 马
                            if (color == ChessCache.Player.BLACK.getValue()) {
                                blackScore = blackScore + FLEXIBLE_HORSE;
                            } else {
                                redScore = redScore + FLEXIBLE_HORSE;
                            }
                        } else if ("elephant".equals(type)) { // 象相
                            if (color == ChessCache.Player.BLACK.getValue()) {
                                blackScore = blackScore + FLEXIBLE_ELEPHANT;
                            } else {
                                redScore = redScore + FLEXIBLE_ELEPHANT;
                            }
                        } else if ("guard".equals(type)) { // 士仕
                            if (color == ChessCache.Player.BLACK.getValue()) {
                                blackScore = blackScore + FLEXIBLE_GUARD;
                            } else {
                                redScore = redScore + FLEXIBLE_GUARD;
                            }
                        } else if ("king".equals(type)) { // 将帅
                            if (color == ChessCache.Player.BLACK.getValue()) {
                                blackScore = blackScore + FLEXIBLE_KING;
                            } else {
                                redScore = redScore + FLEXIBLE_KING;
                            }
                        } else if ("cannon".equals(type)) { // 炮
                            if (color == ChessCache.Player.BLACK.getValue()) {
                                blackScore = blackScore + FLEXIBLE_CANNON;
                            } else {
                                redScore = redScore + FLEXIBLE_CANNON;
                            }
                        } else if ("soldier".equals(type)) { // 卒兵
                            if (color == ChessCache.Player.BLACK.getValue()) {
                                blackScore = blackScore + FLEXIBLE_SOLDIER;
                            } else {
                                redScore = redScore + FLEXIBLE_SOLDIER;
                            }
                        }
                        // 加威胁分（默认再加一遍基础分）
                        int index = this.gamePanel.chessBoradState[row][column];
                        if (index != -1) {
                            String type1 = this.gamePanel.mapChess[index].get("type");
                            if ("rook".equals(type1)) { // 车
                                if (color == ChessCache.Player.BLACK.getValue()) {
                                    blackScore = blackScore + BASE_ROOK;
                                } else {
                                    redScore = redScore + BASE_ROOK;
                                }
                            } else if ("horse".equals(type1)) { // 马
                                if (color == ChessCache.Player.BLACK.getValue()) {
                                    blackScore = blackScore + BASE_HORSE;
                                } else {
                                    redScore = redScore + BASE_HORSE;
                                }
                            } else if ("elephant".equals(type1)) { // 象相
                                if (color == ChessCache.Player.BLACK.getValue()) {
                                    blackScore = blackScore + BASE_ELEPHANT;
                                } else {
                                    redScore = redScore + BASE_ELEPHANT;
                                }
                            } else if ("guard".equals(type1)) { // 士仕
                                if (color == ChessCache.Player.BLACK.getValue()) {
                                    blackScore = blackScore + BASE_GUARD;
                                } else {
                                    redScore = redScore + BASE_GUARD;
                                }
                            } else if ("king".equals(type1)) { // 将帅
                                if (color == ChessCache.Player.BLACK.getValue()) {
                                    blackScore = blackScore + BASE_KING;
                                } else {
                                    redScore = redScore + BASE_KING;
                                }
                            } else if ("cannon".equals(type1)) { // 炮
                                if (color == ChessCache.Player.BLACK.getValue()) {
                                    blackScore = blackScore + BASE_CANNON;
                                } else {
                                    redScore = redScore + BASE_CANNON;
                                }
                            } else if ("soldier".equals(type1)) { // 卒兵
                                if (color == ChessCache.Player.BLACK.getValue()) {
                                    blackScore = blackScore + BASE_SOLDIER;
                                } else {
                                    redScore = redScore + BASE_SOLDIER;
                                }
                            }
                        }
                    }
                }
            }
        }

        // 计算总分
        if (nextColor == ChessCache.Player.RED.getValue()) {
            score = blackScore - redScore;
        } else {
            score = redScore - blackScore;
        }

        return score;
    }

    /**
     * 负极大值算法
     *
     * @param chessBoradMap 棋盘状态信息
     * @param depth         深度
     */
    private int negaMax(int[][] chessBoradMap, int depth) {
        int value;
        int bestValue = -9999999;

        //有事，程序还有好多漏洞，暂时未完善，也没写α与β剪枝，等有空再完善。

        //if(this.gameOver())return evaluation(this.gamePanel.chessBoradState);    //胜负已分，返回估值，有问题

        // System.out.println("_depth="+_depth);

        // 叶子节点
        if (depth == 0) {
            return this.evaluation(this.gamePanel.chessBoradState);    //调用估值函数，返回估值
        }

        // 生成每一步走法
        int nextColor = gamePanel.getNextChessColor();

        // System.out.println("nextColor="+nextColor);

        // 遍历全部棋子
        for (int i = 0; i < this.gamePanel.mapChess.length; i++) {
            // 判断该谁下棋,不是当前方，跳过遍历
            if (Integer.parseInt(this.gamePanel.mapChess[i].get("color")) != nextColor) {
                continue;
            }

            // System.out.println(this.gamePanel.mapChess[i].get("name"));

            // 判断是否可以下棋
            for (int row = 0; row < GamePanel.GRID_ROWS; row++) {
                for (int column = 0; column < GamePanel.GRID_COLUMNS; column++) {
                    // 棋子可以放到目标位置
                    if (this.isAbleToMove(this.gamePanel.mapChess[i], row, column)) {
                        this.moveTo(this.gamePanel.mapChess[i], row, column);

                        // 递归搜索子节点
                        value = -this.negaMax(this.gamePanel.chessBoradState, depth - 1);

                        // 判断最大值
                        if (value >= bestValue) {
                            // 更新最好的分数
                            bestValue = value;

                            // System.out.println("new _depth="+_depth);

                            // 设置AI要走的位置
                            if (depth == this.maxDepth) {
                                this.mapAiChess.put("index", "" + i);
                                this.mapAiChess.put("newRow", row + "");
                                this.mapAiChess.put("newColumn", column + "");
                            }
                        }
                        //恢复原来位置
                        this.undoStep();
                    }
                }
            }
        }

        return bestValue;   //返回最大值
    }

    /**
     * 轮到电脑下棋了
     */
    public void computerPlay() {

        // 估值，无用，在这个方法中已经设置了结果
        int value = this.negaMax(this.gamePanel.chessBoradState, this.maxDepth);

        // AI计算后的坐标
        int index = Integer.parseInt(this.mapAiChess.get("index"));
        int newRow = Integer.parseInt(this.mapAiChess.get("newRow"));
        int newColumn = Integer.parseInt(this.mapAiChess.get("newColumn"));

        // System.out.println("value="+value);
        // System.out.println("index="+index);
        // System.out.println("newRow="+newRow);
        // System.out.println("newColumn="+newColumn);

        // 指定下标的子移动到指定坐标
        this.moveTo(this.gamePanel.mapChess[index], newRow, newColumn);

        // 落子指示器
        this.gamePanel.mapPointerChess.put("row", newRow);
        this.gamePanel.mapPointerChess.put("column", newColumn);
        this.gamePanel.mapPointerChess.put("show", 1);
        this.gamePanel.mapPointerChess.put("color", this.gamePanel.computerChess ? 1 : 0);

        // 刷新界面
        this.gamePanel.repaint();
    }

    /**
     * 得到某棋子的可移动路线
     *
     * @param mapChess 棋子
     */
    private void getMoveRoute(Map<String, String> mapChess) {
		/*if (gamePanel.chineseChess.chessCache.currentUI == ChessDTO.UI.FISH) {
			return;
		}*/
        // 清空移动路线
        this.gamePanel.listMove.clear();

        // 懒得分类挑，反正电脑计算快
        for (int row = 0; row < GamePanel.GRID_ROWS; row++) {
            for (int column = 0; column < GamePanel.GRID_COLUMNS; column++) {
                // 能移至指定坐标，加入落子路线列表
                if (this.isAbleToMove(mapChess, row, column)) {
                    Map<String, Integer> map = new HashMap<String, Integer>();
                    map.put("row", row);
                    map.put("column", column);
                    this.gamePanel.listMove.add(map);
                }
            }
        }

    }

    /**
     * 判断游戏是否结束
     *
     * @return true，游戏结束，否则，false
     */
    boolean gameOver() {
        if (gamePanel.chineseChess.chessCache.currentBattle == ChessCache.Battle.PVC) { // 人机对战
            if ("T".equals(this.gamePanel.mapChess[4].get("dead"))) { // 黑将被吃
                if (!this.gamePanel.computerChess) {
                    JOptionPane.showMessageDialog(gamePanel, "电脑有点蠢，不要太得意哦~");
                } else {
                    JOptionPane.showMessageDialog(gamePanel, "我去，你怎么连电脑都输啊！", "提示", JOptionPane.ERROR_MESSAGE);
                }
                return true;
            }
            if ("T".equals(this.gamePanel.mapChess[27].get("dead"))) { // 红帅被吃
                if (!this.gamePanel.computerChess) {
                    JOptionPane.showMessageDialog(gamePanel, "我去，你怎么连电脑都输啊！", "提示", JOptionPane.ERROR_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(gamePanel, "电脑有点蠢，不要太得意哦~");
                }
                return true;
            }
        } else { // 人人对战
            if ("T".equals(this.gamePanel.mapChess[4].get("dead"))) { // 黑将被吃
                if (!gamePanel.chineseChess.chessCache.currentPlayer) {
                    JOptionPane.showMessageDialog(gamePanel, "胜败乃兵家常事，少侠请重新来过！");
                } else {
                    JOptionPane.showMessageDialog(gamePanel, "汝之秀，吾不能及也！");
                }
                if (gamePanel.chineseChess.chessCache.currentMode == ChessCache.Mode.ONLINE) {
                    this.gamePanel.chineseChess.send(new Point(ChessDTO.Option.GAME_OVER));
                }
                // 游戏结束处理
                gamePanel.gameOver();
                return true;
            }
            if ("T".equals(this.gamePanel.mapChess[27].get("dead"))) { // 红帅被吃
                if (!gamePanel.chineseChess.chessCache.currentPlayer) {
                    JOptionPane.showMessageDialog(gamePanel, "汝之秀，吾不能及也！");
                } else {
                    JOptionPane.showMessageDialog(gamePanel, "胜败乃兵家常事，少侠请重新来过！");
                }

                // 在线模式 - 发送游戏结束消息
                if (gamePanel.chineseChess.chessCache.currentMode == ChessCache.Mode.ONLINE) {
                    this.gamePanel.chineseChess.send(new Point(ChessDTO.Option.GAME_OVER));
                }

                // 游戏结束处理
                gamePanel.gameOver();
                return true;
            }
        }

        return false;
    }

    /**
     * 棋子移动到指定位置
     *
     * @param _mapChess  指定的棋子信息
     * @param _newRow    横坐标
     * @param _newColumn 纵坐标
     */
    void moveTo(Map<String, String> _mapChess, int _newRow, int _newColumn) {
        // 判断是移动还是吃子，即指定下标已经存在棋子了，落子则将已存在的棋子替换为当前棋子
        int newIndex = this.gamePanel.chessBoradState[_newRow][_newColumn];
        if (newIndex != -1) { // 吃子
            //目标棋子清除
            this.gamePanel.mapChess[newIndex].put("dead", "T");
            this.gamePanel.labelChess[newIndex].setBounds(this.gamePanel.gridsLeftX + -2 * this.gamePanel.gridSize - this.gamePanel.chessSize / 2, this.gamePanel.gridsTopY + -2 * this.gamePanel.gridSize - this.gamePanel.chessSize / 2, this.gamePanel.chessSize, this.gamePanel.chessSize);
        }

        //新棋子占位
        int index = Integer.parseInt(_mapChess.get("index"));
        _mapChess.put("oldOldRow", _mapChess.get("oldRow"));
        _mapChess.put("oldOldColumn", _mapChess.get("oldColumn"));
        _mapChess.put("oldRow", _mapChess.get("newRow"));
        _mapChess.put("oldColumn", _mapChess.get("newColumn"));
        _mapChess.put("newRow", Integer.toString(_newRow));
        _mapChess.put("newColumn", Integer.toString(_newColumn));
        _mapChess.put("oldEatIndex", _mapChess.get("eatIndex"));
        _mapChess.put("eatIndex", Integer.toString(newIndex));
        this.addList(_mapChess);

        // 设置棋子新位置
        this.gamePanel.labelChess[index].setBounds(this.gamePanel.gridsLeftX + _newColumn * this.gamePanel.gridSize - this.gamePanel.chessSize / 2, this.gamePanel.gridsTopY + _newRow * this.gamePanel.gridSize - this.gamePanel.chessSize / 2, this.gamePanel.chessSize, this.gamePanel.chessSize);
        // 旧位置设置为无棋子
        this.gamePanel.chessBoradState[Integer.parseInt(_mapChess.get("oldRow"))][Integer.parseInt(_mapChess.get("oldColumn"))] = -1;
        // 设置新位置的棋子类别，后面可以通过index找到棋子相关信息
        this.gamePanel.chessBoradState[_newRow][_newColumn] = index;
        // 设置为第一次点击
        this.gamePanel.isFirstClick = true;
    }

    /**
     * 功能：鼠标单击事件<br>
     */
    public void mouseClicked(MouseEvent e) {
        // 已落子或游戏结束，跳过
        if (gamePanel.chineseChess.chessCache.put || this.gamePanel.isGameOver) {
            return;
        }

        // 鼠标左键点击
        if (e.getButton() == MouseEvent.BUTTON1) {
            if (e.getSource() == this.gamePanel.labelChessBorad) {  // 点击到棋盘上
                // 第一次点击无效，即已点击，跳过
                if (this.gamePanel.isFirstClick) {
                    return;
                }

                // 判断位置（将X与Y由像素改为相应的行列坐标）
                int row = this.getRow(e.getY());
                int column = this.getColumn(e.getX());
                if (row >= 0 && row < 10 && column >= 0 && column < 9) {   //第二次点击
                    //要移动棋子了
                    if (this.isAbleToMove(this.gamePanel.firstClickChess, row, column)) {
                        // 移动至指定位置
                        this.moveTo(this.gamePanel.firstClickChess, row, column);
                        //取消移动路线图
                        this.gamePanel.listMove.clear();
                        //落子指示器
                        this.gamePanel.mapPointerChess.put("row", row);
                        this.gamePanel.mapPointerChess.put("column", column);
                        this.gamePanel.mapPointerChess.put("show", 1);
                        //更新提示
                        if (Integer.parseInt(gamePanel.firstClickChess.get("color")) == ChessCache.Player.BLACK.getValue()) {
                            this.gamePanel.jlb_redStateText.setText("思考中");
                            this.gamePanel.jlb_blackStateText.setText(getPrompt(this.gamePanel.firstClickChess));
                        } else {
                            this.gamePanel.jlb_redStateText.setText(getPrompt(this.gamePanel.firstClickChess));
                            this.gamePanel.jlb_blackStateText.setText("思考中");
                        }
                        // 刷新界面
                        this.gamePanel.repaint();
                        // 处理移动数据
                        processMoveData(row, column);
                    }
                }
            } else { //点到棋子上
                JLabel label = (JLabel) e.getSource();
                int index = Integer.parseInt(label.getName());
                int row = Integer.parseInt(this.gamePanel.mapChess[index].get("newRow"));
                int column = Integer.parseInt(this.gamePanel.mapChess[index].get("newColumn"));
                //判断第几次点击
                if (this.gamePanel.isFirstClick) { // 第一次（必须点击到该下棋方的棋子上）
                    // 设置当前玩家颜色
                    boolean currentPlayer = gamePanel.chineseChess.chessCache.currentPlayer;
                    if (ChessCache.Mode.OFFLINE == gamePanel.chineseChess.chessCache.currentMode) {
                        currentPlayer = gamePanel.getNextChessColor() == 1 ? true : false;
                    }

                    // 指定棋子颜色与当前所属颜色不一致，跳过
                    boolean color = Integer.parseInt(this.gamePanel.mapChess[index].get("color")) == 1 ? true : false;
                    if (color != currentPlayer) {
                        return;
                    }

                    //画个落子指示器并记录下第一次点击对象
                    this.gamePanel.mapPointerChess.put("row", row);
                    this.gamePanel.mapPointerChess.put("column", column);
                    this.gamePanel.mapPointerChess.put("show", 1);
                    this.gamePanel.mapPointerChess.put("color", Integer.parseInt(this.gamePanel.mapChess[index].get("color")));
                    this.gamePanel.firstClickChess = this.gamePanel.mapChess[index];
                    this.gamePanel.isFirstClick = false;
                    // 刷新界面
                    this.gamePanel.repaint();

                    // 更新提示
                    if (Integer.parseInt(this.gamePanel.mapChess[index].get("color")) == ChessCache.Player.BLACK.getValue()) {
                        this.gamePanel.jlb_redStateText.setText("等待中");
                        this.gamePanel.jlb_blackStateText.setText("已选棋");
                    } else {
                        this.gamePanel.jlb_redStateText.setText("已选棋");
                        this.gamePanel.jlb_blackStateText.setText("等待中");
                    }
                    //显示移动路线图
                    this.getMoveRoute(this.gamePanel.firstClickChess);
                    // 刷新界面
                    this.gamePanel.repaint();

                } else { // 第二次点击
                    // 点击到该下棋方的棋子上则还算是第一次
                    // 设置当前玩家颜色
                    boolean currentPlayer = gamePanel.chineseChess.chessCache.currentPlayer;
                    if (ChessCache.Mode.OFFLINE == gamePanel.chineseChess.chessCache.currentMode) {
                        currentPlayer = gamePanel.getNextChessColor() == 1 ? true : false;
                    }


                    // 棋子与颜色匹配一致，
                    boolean color = Integer.parseInt(this.gamePanel.mapChess[index].get("color")) == 1 ? true : false;
                    if (color == currentPlayer) {
                        // 画个落子指示器并记录下点击对象
                        this.gamePanel.mapPointerChess.put("row", row);
                        this.gamePanel.mapPointerChess.put("column", column);
                        this.gamePanel.mapPointerChess.put("show", 1);
                        this.gamePanel.firstClickChess = this.gamePanel.mapChess[index];
                        this.gamePanel.isFirstClick = false;

                        // 显示移动路线图
                        this.getMoveRoute(this.gamePanel.firstClickChess);
                        // 刷新界面
                        this.gamePanel.repaint();

                    } else { // 要吃棋子了
                        if (this.isAbleToMove(this.gamePanel.firstClickChess, row, column)) { // 这个可以吃
                            // 移动至指定位置
                            this.moveTo(this.gamePanel.firstClickChess, row, column);
                            // 取消移动路线图
                            this.gamePanel.listMove.clear();
                            // 落子指示器
                            this.gamePanel.mapPointerChess.put("row", row);
                            this.gamePanel.mapPointerChess.put("column", column);
                            this.gamePanel.mapPointerChess.put("show", 1);

                            // 更新提示
                            if (Integer.parseInt(gamePanel.firstClickChess.get("color")) == ChessCache.Player.BLACK.getValue()) {
                                this.gamePanel.jlb_redStateText.setText("思考中");
                                this.gamePanel.jlb_blackStateText.setText(getPrompt(this.gamePanel.firstClickChess));
                            } else {
                                this.gamePanel.jlb_redStateText.setText(getPrompt(this.gamePanel.firstClickChess));
                                this.gamePanel.jlb_blackStateText.setText("思考中");
                            }

                            // 刷新界面
                            this.gamePanel.repaint();
                            // 处理移动数据
                            processMoveData(row, column);
                        }

                        //判断双方是否战平（这个不行啊）
                    }
                }
            }
        }

    }

    /**
     * 处理移动数据
     *
     * @param row    行
     * @param column 列
     */
    private void processMoveData(int row, int column) {
        // 判断是否将军
        if (this.check(gamePanel.chineseChess.chessCache.currentPlayer)) {
            return;
        }
        // 如果可以悔棋，则启用悔棋按钮
        if (gamePanel.canRepent()) {
            this.gamePanel.jb_undo.setEnabled(true);
        } else {
            // 悔棋按钮禁用
            this.gamePanel.jb_undo.setEnabled(false);
        }
        // 在线模式
        if (gamePanel.chineseChess.chessCache.currentMode == ChessCache.Mode.ONLINE) {
            // 更新“落子”标识
            gamePanel.chineseChess.chessCache.put = true;
            // 发送落子信息
            this.gamePanel.chineseChess.send(new Point(row, column, gamePanel.chineseChess.chessCache.currentPlayer, Integer.parseInt(gamePanel.firstClickChess.get("index"))));

            //判断游戏是否结束
            if (this.gameOver()) {
                this.gamePanel.isGameOver = true;
                this.gamePanel.setComponentState(false);
                this.gamePanel.jlb_blackStateText.setText("已结束");
                this.gamePanel.jlb_redStateText.setText("已结束");
            }
        } else { // 离线模式
            // 游戏结束，跳过
            if (this.gamePanel.isGameOver) {
                return;
            }

            // 游戏结束,更新标识，更新提示文本，禁用“悔棋”,“投降”按钮
            if (this.gameOver()) {
                this.gamePanel.isGameOver = true;
                this.gamePanel.setComponentState(false);
                this.gamePanel.jlb_blackStateText.setText("已结束");
                this.gamePanel.jlb_redStateText.setText("已结束");
                return;
            }

            //如果是人机对战，机器要回应啊
            if (gamePanel.chineseChess.chessCache.currentBattle == ChessCache.Battle.PVC) {
                // 电脑落子
                computerRun();
            }
        }
    }

    /**
     * 电脑落子
     */
    private void computerRun() {
        this.computerPlay();
        // 变更落子状态
        if (!this.gamePanel.computerChess) {
            this.gamePanel.jlb_blackStateText.setText(getPrompt(this.gamePanel.firstClickChess));
            this.gamePanel.jlb_redStateText.setText("思考中");
        } else {
            this.gamePanel.jlb_redStateText.setText(getPrompt(this.gamePanel.firstClickChess));
            this.gamePanel.jlb_blackStateText.setText("思考中");
        }
    }

    /**
     * 鼠标移动事件<br>
     */
    public void mouseMoved(MouseEvent e) {
        int row;
        int column;
        int index = -1;
        // 游戏结束，跳过
        if (this.gamePanel.isGameOver) {
            return;
        }

        // 得到行列位置
        if (e.getSource() == this.gamePanel.labelChessBorad) { // 在棋盘上移动
            row = this.getRow(e.getY());
            column = this.getColumn(e.getX());
        } else { // 在棋子上移动
            JLabel label = (JLabel) e.getSource();
            index = Integer.parseInt(label.getName());
            row = Integer.parseInt(this.gamePanel.mapChess[index].get("newRow"));
            column = Integer.parseInt(this.gamePanel.mapChess[index].get("newColumn"));
        }

        // 判断是否在棋盘内部移动
        if (row >= 0 && row < 10 && column >= 0 && column < 9) {
            // 清除落子指示器（先不显示）
            this.gamePanel.mapPointerMove.put("show", 0);
            if (this.gamePanel.chessBoradState[row][column] == -1) { // 移动到棋盘上
                this.gamePanel.mapPointerMove.put("row", row);
                this.gamePanel.mapPointerMove.put("column", column);
                this.gamePanel.mapPointerMove.put("show", 1);
                this.gamePanel.mapPointerMove.put("color", -1);
            } else { // 移动到棋子上
                // 第一次点击处理
                if (this.gamePanel.isFirstClick) {
                    if (Objects.nonNull(gamePanel.chineseChess.chessCache)) {
                        //下棋方显示移动显示器，非下棋方不显示移动指示器
                        boolean currentPlayer = gamePanel.chineseChess.chessCache.currentPlayer;
                        if (ChessCache.Mode.OFFLINE == gamePanel.chineseChess.chessCache.currentMode) {
                            currentPlayer = gamePanel.getNextChessColor() == 1 ? true : false;
                        }

                        boolean play = Integer.parseInt(this.gamePanel.mapChess[index].get("color")) == 1 ? true : false;
                        if (play == currentPlayer) {
                            // 画个落子指示器并记录对象
                            this.gamePanel.mapPointerMove.put("row", row);
                            this.gamePanel.mapPointerMove.put("column", column);
                            this.gamePanel.mapPointerMove.put("show", 1);
                            this.gamePanel.mapPointerMove.put("color", -1);
                        }
                    }
                } else { // 第二次点击处理
                    this.gamePanel.mapPointerMove.put("row", row);
                    this.gamePanel.mapPointerMove.put("column", column);
                    this.gamePanel.mapPointerMove.put("show", 1);
                    this.gamePanel.mapPointerMove.put("color", -1);
                }
            }
            // 刷新界面
            this.gamePanel.repaint();

        } else { // 点棋盘外边了
            if (this.gamePanel.mapPointerMove.get("show") == 1) {
                this.gamePanel.mapPointerMove.put("show", 0);
                // 刷新界面
                this.gamePanel.repaint();
            }
        }

    }

    String getPrompt(Map<String, String> mapChess) {
        if (gamePanel.chineseChess.chessCache.currentMode == ChessCache.Mode.OFFLINE) {
            return "已下完";
        }

        // 棋子名称
        String one = mapChess.get("name").split("")[1];

        Integer newRow = 9 - Integer.parseInt(mapChess.get("newRow"));
        int newColumn = 8 - Integer.parseInt(mapChess.get("newColumn"));

        Integer oldRow = 9 - Integer.parseInt(mapChess.get("oldRow"));
        int oldColumn = 8 - Integer.parseInt(mapChess.get("oldColumn"));

        // 行不变：平 否则：进/退 （下方： 负=进）
        int num = oldRow - newRow;

        // 老列号
        int two = oldColumn + 1;

        // 有意思
        String three = num == 0 ? "平" : num > 0 ? "退" : "进";

        // 有东西
        int four = num == 0 ? newColumn + 1 : (oldColumn - newColumn == 0) ? Math.abs(num) : newColumn + 1;

        // 下面从左往右 1-9
        // 下面从下到上 1-10

        // 上面从右往左 1-9
        // 上面从上到下 1-10
        String title = one + two + three + four;
        return title;
    }

    String getOtherSidePrompt(Map<String, String> mapChess) {
        if (gamePanel.chineseChess.chessCache.currentMode == ChessCache.Mode.OFFLINE) {
            return "已下完";
        }

        // 棋子名称
        String one = mapChess.get("name").split("")[1];

        Integer newRow = Integer.parseInt(mapChess.get("newRow"));
        int newColumn = Integer.parseInt(mapChess.get("newColumn"));

        Integer oldRow = Integer.parseInt(mapChess.get("oldRow"));
        int oldColumn = Integer.parseInt(mapChess.get("oldColumn"));

        // 行不变：平 否则：进/退 （下方： 负=进）
        int num = oldRow - newRow;

        // 老列号
        int two = oldColumn + 1;

        // 有意思
        String three = num == 0 ? "平" : num > 0 ? "退" : "进";

        // 有东西
        int four = num == 0 ? newColumn + 1 : (oldColumn - newColumn == 0) ? Math.abs(num) : newColumn + 1;

        // 下面从左往右 1-9
        // 下面从下到上 1-10

        // 上面从右往左 1-9
        // 上面从上到下 1-10
        String title = one + two + three + four;
        return title;
    }

}
